package com.amos.teaching_aids.ui.Fragment;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.INotificationSideChannel;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import com.amos.teaching_aids.R;
import com.amos.teaching_aids.SysApplication;
import com.amos.teaching_aids.UserInfo;
import com.amos.teaching_aids.presenter.UserPresenter;
import com.amos.teaching_aids.ui.Interface.IUserBetterView;
import com.amos.teaching_aids.ui.MainActivity;
import com.amos.teaching_aids.ui.activity.BaseActivity;
import com.amos.teaching_aids.ui.activity.CustomDialog;
import com.amos.teaching_aids.ui.activity.UserInfoActivity;
import com.amos.teaching_aids.ui.activity.UserLoginActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/10/8 0008.
 */

public class UserBetterFragment extends UserFragment implements IUserBetterView, View.OnClickListener{
    protected ProgressDialog progressDialog = new ProgressDialog(SysApplication.getContext());
    private UserPresenter mUserPresenter;
    private BaseActivity loginView;
    private Button login, logout;

    private View mView;
    @Override
    public void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUserPresenter = new UserPresenter(this, null, null);
        loginView = new UserLoginActivity();

    }
    @Override
    public int getLayout(){
        return R.layout.fragment_better;
    }

    @Override
    protected void initView(View view) {
        login = (Button) view.findViewById(R.id.button_login);
        logout = (Button) view.findViewById(R.id.button_logout);

        mView = view.findViewById(R.id.short_info);
        mView.setOnClickListener(this);
        login.setOnClickListener(this);
        logout.setOnClickListener(this);
        progressDialog.setMessage("注销中...");
        progressDialog.setCancelable(false);
    }

    @Override
    public void showLoding() {
        progressDialog.show();

    }

    @Override
    public void hideLoding() {
        progressDialog.dismiss();

    }

    @Override
    public void showLogoutSuc() {
        Toast.makeText(SysApplication.getContext(), "注销成功", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showLogoutFail(String errorReason) {
        Toast.makeText(SysApplication.getContext(), "注销失败" + errorReason, Toast.LENGTH_SHORT).show();

    }
    private void login(){
        Intent intent = new Intent(this.getActivity(), UserLoginActivity.class);
        startActivity(intent);


    }
    private void logout(){
        AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
        dialog.setMessage("确定要注销吗?");
        dialog.setCancelable(false);
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mUserPresenter.logout();
            }
        });
        dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialog.show();

    }
    private void showUserInfo(){
        Intent intent = new Intent(this.getActivity(), UserInfoActivity.class);
        this.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_login:
                login();
                break;
            case R.id.short_info:
                showUserInfo();
                break;

        }
    }
}
